// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
//使用vuex
import store from './store'
import router from './router'
//引入公共样式
import './assets/css/common.css'
import './assets/iconfont/iconfont.css'
//引入iview组件库样式
import 'view-design/dist/styles/iview.css';
//按需引入
import { Layout, Header, Sider, Content } from 'view-design';
Vue.component('Layout', Layout);
Vue.component('Header', Header);
Vue.component('Sider', Sider);
Vue.component('Content', Content);
import { Menu, MenuItem, Icon } from 'view-design';
Vue.component('Menu', Menu);
Vue.component('MenuItem', MenuItem);
Vue.component('Icon', Icon);
import { Table, Button } from 'view-design';
Vue.component('Table', Table);
Vue.component('Button', Button);
import { Form, FormItem, Input } from 'view-design';
Vue.component('Form', Form);
Vue.component('FormItem', FormItem);
Vue.component('Input', Input);
import { Message, Checkbox, Progress, Modal, Tabs, TabPane, Upload, Page, Tree, CheckboxGroup, Switch } from 'view-design';
Vue.prototype.$Message = Message
Vue.prototype.$Modal = Modal
Vue.component('Checkbox', Checkbox);
Vue.component('Progress', Progress);
Vue.component('Modal', Modal);
Vue.component('Tabs', Tabs);
Vue.component('TabPane', TabPane);
Vue.component('Page', Page);
Vue.component('Tree', Tree);
Vue.component('CheckboxGroup', CheckboxGroup);
Vue.component('Upload', Upload);
Vue.component('Icon', Icon);
// 不能和html标签重复的组件，添加别名(除了Switch、Circle在使用中必须是iSwitch、iCircle,其他都可以不加"i")
Vue.component('iSwitch', Switch);
//使用axios
import axios from 'axios'
axios.defaults.baseURL = 'http://47.98.149.61:10002'
axios.defaults.timeout = 10000
    //添加一个请求拦截器
axios.interceptors.request.use(config => {
    //使用qs工具对data数据进行序列化处理,然后进行请求的发送处理
    config.headers.Authorization = 'Bearer ' + window.sessionStorage.getItem('token')
    return config
}, (err) => {
    return Promise.reject(err);
})

Vue.prototype.$axios = axios
    //实现图片预览
import 'viewerjs/dist/viewer.css'
import VueViewer from 'v-viewer'
Vue.use(VueViewer)

Vue.config.productionTip = false

// 路由拦截
router.beforeEach((to, from, next) => {
    if (to.path.indexOf('/admin') == 0) {
        let session = window.sessionStorage.getItem('token')
        TODO:
            // 向后端发送请求确定session是否正确
            if (!session) {
                if (from.path != '/') {
                    next('/')
                } else {
                    return
                }
            }
    }
    next()
})

import moment from 'moment/moment'
//时间过滤
Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
    return moment(dataStr).format(pattern)
})

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    components: { App },
    template: '<App/>'
})